﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_GL_SYSTEM_H
#define _UXS_GL_SYSTEM_H

#pragma once

#include "GLBatchRender.h"
#include "GLMatrixStack.h"
#include "../shell/GLObjectManager.h"
#include "GLViewport.h"


namespace UX_STL
{
namespace GLShell
{

	//
	// Render
	//

	class UX_EXPORT GLSystem : public GLBaseObject
	{
	protected:
		// Systems //
		GLStateManager			_cStMan;
		GLBatchRender			_cBatchRender;
		GLMatrixStack			_cMStack;

		// Const //
		uint					_uGLSLVersion,
								_uGLVersion;
		
		Bytes					_totalVRAM;	// Mb
		e_gpu_model::type		_eGPUModel;

	private:
		static void CALLBACK _s_DebugOutput(GLenum source, GLenum type, GLuint id,
											GLenum severity, GLsizei length,
											const GLchar* message, GLvoid* userParam);

	protected:
		bool _Init();
		void _Destroy();

	public:
		GLSystem();
		~GLSystem();


		// Debug //
		bool  InitDebugOutput(bool bSync = true);
		bool  SetDebugCallBack(PGLDebugProc_t pProc = null, void *pParametr = null);


		// Utils //
		void  GetOpenGLInfo(string &sInfo) const;
		void  GetOpenGLParams(string &sParams) const;
		bool  IsExtSupported(const char *pExtName) const;
		void  GetVideoMemory(Bytes &total, Bytes &free) const;

		uint  GLVersion()					const		{ return _uGLVersion; }
		uint  GLSLVersion()					const		{ return _uGLSLVersion; }

		e_gpu_model::type	GetGPUModel()	const		{ return _eGPUModel; }
		

		// Matrix //
		void GetWorldPos(const uvec2 &sOnScr, fvec3 &sPoint)		const;
		void GetScreenPos(const fvec3 &sPoint, uvec2 &sOnScr)		const;
		void GetScreenDepth(const uvec2 &vOnScr, float &fDepth)		const;
		void GetNearPlanePos(const uvec2 &sOnScr, fvec3 &sPoint)	const;
		void GetFarPlanePos(const uvec2 &sOnScr, fvec3 &sPoint)		const;
	};

//-------------------------------------------------------------------

}	// GLShell
}	// UX_STL

#endif	// _UXS_GL_SYSTEM_H